import ReactDOM from "react-dom/client";
import Loading from "./Loading";
import "./Loading.less";

let count = 0;

export const showLoading = () => {
  if (count === 0) {
    const dom = document.createElement("div");
    dom.setAttribute("id", "loading");
    document.body.appendChild(dom);
    ReactDOM.createRoot(dom).render(<Loading />);
  }
  count++;
};

export const hideLoading = () => {
  count--;
  if (count === 0) {
    // const loading = document.getElementById('loading')
    // loading?.style.setProperty('display', 'none')
    document.body.removeChild(
      document.getElementById("loading") as HTMLDivElement
    );
  }
};
